package com.mulanweb.db.common;

import com.mulanweb.handler.wechat.TokenHandler;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

/**
 * Created by Administrator on 2016/8/9.
 */
public class Constant {

    public static class WeChatFinalValue{
        //正式环境APPID
        public static final String APPID = "wx1a5d74a8c7cb135e" ;
        //测试环境APPID
        //public static final String APPID = "wx323bd2d11b36dd8d" ;

        //正式环境APPSECRET
        public static final String APPSECRET = "809f5876bf8a6da66df034f42b8f9517" ;

        //测试环境APPSECRET
        // public static final String APPSECRET = "f5d16665d410f668e32cec3b36463747";

        //会飞翔的神秘空间APPID
        //public static final String APPID = "wx535b34b713e8f7a3" ;
        //会飞翔的神秘空间APPSECRET
        //public static final String APPSECRET = "071694bf9d6ec98f46a1f3cae3937fab";

        //商户id
        public static final String MCHID = "1377954502";

        //测试环境APPSECRET
        //public static final String APPSECRET = "f5d16665d410f668e32cec3b36463747" ;

        /**
         * 创建菜单的url
         * 需要替换ACCESS_TOKEN
         */
        public static final String CREATE_MENU_URL= "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";

        /**
         * 获取prepay_id 接口地址（统一下单接口）
         */
        public static final String GET_PREPAYID_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder";

        /**
         * 微信商户平台向用户打款
         */
        public static final String WECHAT_PAYMENT_USER = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";

        /**
         * 微信商户平台向用户订单退款
         */
        public static final String WECHAT_REFUND_USER = "https://api.mch.weixin.qq.com/secapi/pay/refund";

        /**
         * 查询微信退款
         */
        public static final String WECHAT_QUERY_REFUND_USER  ="https://api.mch.weixin.qq.com/pay/refundquery";

        /**
         * 查询订单的接口地址
         */
        public static final String QUERY_ORDER_URL = "https://api.mch.weixin.qq.com/pay/orderquery";

        //请求用户授权URL，当 scope=snsapi_userinfo 为弹出授权页面，用户没关注也可获取相关信息，
        // scope=snsapi_base 为静默授权，用户无感知可获取相关信息
        public static final String GET_AUTHORIZE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&" +
                "redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect" ;

        public static String getAuthorizeUrl(String redirect_url, String code, String scope, String state){
            return GET_AUTHORIZE_URL.replace("REDIRECT_URL",redirect_url).replace("code",code).replace("scope",scope).replace("STATE",state);
        }

        public static final String GET_WEB_AUTHORIZE_ACCESS_TOKEN = " https://api.weixin.qq.com/sns/oauth2/access_token" +
                "?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
        public static String getWebAuthorizeAccessToken(String code){
                return GET_WEB_AUTHORIZE_ACCESS_TOKEN.replace("APPID",APPID).replace("SECRET",APPSECRET).replace("CODE",code);
        }

        public static String getAuthorizeUrl(String redirect_url, String code, String scope){
            return getAuthorizeUrl(redirect_url,code,scope,null);
        }

        /**
         * 得到创建菜单URL
         * @param access_token 微信交互令牌
         * @return  创建菜单网址
         */
        public static String getCreateMenuUrl(String access_token){
            if(access_token !=null && access_token.length()>0)
                return CREATE_MENU_URL.replace("ACCESS_TOKEN",access_token);
            else
                return null;
        }

        /**
         * 获取access_token的地址
         */
        public static final String GET_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";

        /**
         * 获取 jsApiTicket 的地址
         */
        public static final String GET_JSAPI_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi" ;

        /**
         * 得到获取jsApiTicket url
         * @return jsApiTicket url
         */
        public static String getJsApiTicket(){
            String token = TokenHandler.getAccessToken();
            System.out.println("---token---:"+token);
            return GET_JSAPI_TICKET_URL.replace("ACCESS_TOKEN",token);
        }

        /**
         * 得到获取access_token url
         * @return 获取access_token url
         */
        public static String getGetAccessTokenUrl(){
            return GET_ACCESS_TOKEN_URL.replace("APPID",APPID).replace("APPSECRET",APPSECRET);
        }

        /**
         * 获取微信服务器地址的URL
         * 需要替换ACCESS_TOKEN
         */
        public static final String WECHAT_SERVER_IP_DRIVER_URL = "https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=ACCESS_TOKEN";

        public static String getWechatServerIpDriverUrl(String access_token){
            if(access_token !=null && access_token.length()>0)
                return WECHAT_SERVER_IP_DRIVER_URL.replace("ACCESS_TOKEN",access_token);
            else
                return null;
        }

        /**
         * 获取用户详细信息的URL
         * 需要替换ACCESS_TOKEN，OPENID
         */
        public static final String GET_USER_DETAIL_URL = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";

        /**
         * 得到获取用户详细信息的url
         * @param access_token 微信交互令牌
         * @param openid 用户主键
         * @param lang 返回语言 默认为 zh_CN
         * @return 获取用户详细信息的url
         */
        public static String getGetUserDetailUrl(String access_token, String openid, String lang){
            if(access_token !=null && openid != null){
                lang = lang != null ? lang : "zh_CN" ;
                return GET_USER_DETAIL_URL.replace("ACCESS_TOKEN",access_token).replace("OPENID",openid).replace("zh_CN",lang);
            }else{
                return null ;
            }
        }

        /**
         * 得到获取用户详细信息的url
         * @param access_token 微信交互令牌
         * @param openid 用户主键
         * @return 获取用户详细信息的url
         */
        public static String getGetUserDetailUrl(String access_token, String openid){
            return getGetUserDetailUrl(access_token, openid, null);
        }

        /**
         * 消息类型：文本
         */
        public static final String MSG_TEXT_TYPE = "text" ;

        /**
         * 消息类型：图片
         */
        public static final String MSG_IMAGE_TYPE = "image";

        /**
         * 消息类型：语音
         */
        public static final String MSG_VOICE_TYPE = "voice";

        /**
         * 消息类型：视屏
         */
        public static final String MSG_VIDEO_TYPE = "video";

        /**
         * 消息类型：小视屏
         */
        public static final String MSG_SHORTVIDEO_TYPE= "shortvideo";

        /**
         * 消息类型：地理位置
         */
        public static final String MSG_LOCATION_TYPE = "LOCATION";

        /**
         * 消息类型：链接
         */
        public static final String MSG_LINK_TYPE = "link";


        /**
         * 返回消息类型：音乐
         */
        public static final String RESP_MESSAGE_MUSIC_TYPE= "music";

        /**
         * 返回消息类型：图文
         */
        public static final String RESP_MESSAGE_NEWS_TYPE = "news";

        /**
         * 消息类型：推送
         */
        public static final String MESSAGE_EVENT_TYPE = "event";

        /**
         * 事件类型：subscribe(订阅)
         */
        public static final String EVENT_SUBSCRIBE_TYPE = "subscribe";

        /**
         * 事件类型：unsubscribe(取消订阅)
         */
        public static final String EVENT_UNSUBSCRIBE_TYPE = "unsubscribe";

        /**
         * 事件类型：CLICK(自定义菜单点击事件)
         */
        public static final String EVENT_CLICK_TYPE = "CLICK";
    }

    public static class XinXiLan{

        /**
         * 支付成功回调网址(订单列表)
         */
        public static final String PAY_SUCCESS_PAGE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1a5d74a8c7cb135e&redirect_uri=http%3a%2f%2fweixin.mulanweb.com%2fadmin%2ftest%2fgetAuthority&response_type=code&scope=snsapi_base&state=order#wechat_redirect";

        /**
         * 支付失败回调网址(订单列表)
         */
        public static final String PAY_FAIL_PAGE_URL="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1a5d74a8c7cb135e&redirect_uri=http%3a%2f%2fweixin.mulanweb.com%2fadmin%2ftest%2fgetAuthority&response_type=code&scope=snsapi_base&state=order#wechat_redirect";

        /**
         * 验证码过期时间，单位为天
         */
        public static final Integer VERIFY_CODE_OVERTIME = 30;

        /**
         * 商户后台登陆地址
         */
        public static final String SELLER_LOGIN_URL ="/common/login/seller_login.jsp";
        /**
         * 商户后台登陆错误地址
         */
        public static final String SELLER_LOGIN_URL_ERROR = "/common/login/seller_login.jsp?login_error";

        /**
         * 管理员登陆后台地址
         */
        public static final String ADMIN_LOGIN_URL = "/common/login/index.jsp";

        /**
         * 管理员登陆后台错误地址
         */
        public static final String ADMIN_LOGIN_URL_ERROR="/common/login/index.jsp?login_error";

        /**
         * 默认照片地址
         */
        public static final String DEFAULT_PHOTO_PATH = "http://wx.qlogo.cn/mmopen/Mia8pfWBgY9EMq10jnF1w75tIbYjpk4VHdQHia5x0yalMD1oDEx3kxlm8cBiaNUzlsbs4J6ktn4G9IXBFqvviamRj4nRqVAfMBU7/0";

        /**
         * 管理员登陆标记
         */
        public static final String ADMIN_LOGIN_TAG = "XINXILAN_YES_LGOIN";

        /**
         * 商家登陆标记
         */
        public static final String SELLER_LOGIN_TAG = "SELLER_YES_LOGIN";

        /**
         * 兑换码解码钥匙
         */
        public static final String ORDER_AES_KEY="mulan_xxl_verify_decrypt";
    }

    public static class ContextPatameter{

        /**
         * 商品汇率
         */
        public static final String EXCHANGE_RATE = "4.9";

        /**
         * 保存内容图片到本地的位置
         */
        //public static final String PHOTO_SAVE_PATH ="D:\\workspace\\mulan_xxl\\src\\main\\webapp\\static\\view-img\\";
        //public static final String PHOTO_SAVE_PATH ="D:\\website\\mulan_xxl\\static\\view-img\\";

        public static final String PHOTO_SAVE_PATH ="D:/website/mulan_xxl/static/view-img/";

        /**
         * 订单交易成功发送模板消息时，点击模板消息回调网址,注意带参数，参数为订单号
         */
        public static final String ORDER_DETAIL_PATH="weixin.mulanweb.com/view/menu3/order/detail.jsp?orderNumber=";

        /**
         * 微信转账证书文件位置
         */
        public static final String PAY_CERTIFICATE_URL = "D:/apiclient_cert.p12";

    }

    public static class PromptMessage{
        /**
         * 当用户不存在时的提示
         */
        public static final String NOT_EXIST_USER = "您的信息未同步,请尝试重新关注该公众号！" ;

        public static final String VERIFY_FAIL = "Validation failed, the code is invalid or already used";

        public static String VERIFY_SUCCESS(int person){
            return "Successful validation，this code is validated for "+ person + " people";
        }
    }

    public static class Event{

        /**
         * 一等奖券码
         */
        public static final String COUPON_CODE_1 =  "31807502" ;

        /**
         * 二等奖券码
         */
        public static final String COUPON_CODE_2 =  "55684046" ;

        /**
         * 三等奖券码
         */
        public static final String COUPON_CODE_3 =  "66713045" ;


        /**
         * 用户完成活动 辛苦奖
         */
        public static final String COUPON_CODE_4 =  "69556154" ;


        /**
         * 用户参加活动 安慰奖
         */
        public static final String COUPON_CODE =  "73245647" ;


    }

}
